package com.wxapp.sale.service.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wxapp.common.constant.base.IBaseController;
import com.wxapp.common.constant.pojo.vm.ResultVm;
import com.wxapp.common.constant.pojo.vo.UserVo;
import com.wxapp.common.core.annotation.User;
import com.wxapp.common.core.filter.except.ThrowMyException;
import com.wxapp.sale.api.pojo.vm.goods.PGoodsAddFileVm;
import com.wxapp.sale.api.pojo.vm.goods.PGoodsDetailVm;
import com.wxapp.sale.api.pojo.vm.goods.PGoodsPageVm;
import com.wxapp.sale.api.pojo.vo.goods.QGoodsAddFileVo;
import com.wxapp.sale.api.pojo.vo.goods.QGoodsAddVo;
import com.wxapp.sale.api.pojo.vo.goods.QGoodsPageVo;
import com.wxapp.sale.api.pojo.vo.goods.QGoodsUpdateVo;
import com.wxapp.sale.service.service.GoodsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lgl
 */
@RestController
@RequestMapping("goods")
@Tag(name = "商品")
@RequiredArgsConstructor
public class GoodsController extends IBaseController {
    private final GoodsService goodsService;

    @PostMapping("add")
    @Operation(summary ="添加商品")
    public ResultVm<String> add(@RequestBody @Validated QGoodsAddVo qGoodsAddVo, @Schema(hidden = true) @User UserVo userVo) {
        return goodsService.add(qGoodsAddVo, userVo);
    }

    @PutMapping("update")
    @Operation(summary ="更新商品")
    public ResultVm<String> update(@RequestBody @Validated QGoodsUpdateVo qGoodsUpdateVo, @Schema(hidden = true) @User UserVo userVo) {
        return goodsService.update(qGoodsUpdateVo, userVo);
    }

    @PostMapping("page")
    @Operation(summary ="获取商品列表")
    public ResultVm<Page<PGoodsPageVm>> page(@RequestBody QGoodsPageVo qPageVo, @Schema(hidden = true) @User UserVo userVo) {
        return goodsService.page(qPageVo,userVo);
    }

    @DeleteMapping("delete/{id}")
    @Operation(summary ="删除商品")
    public ResultVm<String> delGoods(@PathVariable String id) {
        return goodsService.delGoods(id);
    }

    @GetMapping("/detail/{id}")
    @Operation(summary ="获取商品详细信息")
    public ResultVm<PGoodsDetailVm> detail(@PathVariable String id) throws ThrowMyException {
        return goodsService.detail(id);
    }

    @PostMapping("addFile/{id}")
    @Operation(summary ="添加商品附件")
    public ResultVm<String> addFile(@PathVariable String id, @RequestBody @Validated QGoodsAddFileVo qAddVo, @Schema(hidden = true) @User UserVo userVo) {
        return goodsService.addFile(id,qAddVo, userVo);
    }
    @GetMapping("getFiles/{id}")
    @Operation(summary ="添加商品附件")
    public ResultVm<PGoodsAddFileVm> getFiles(@PathVariable String id) {
        return goodsService.getFiles(id);
    }

    @PostMapping("list")
    @Operation(summary ="获取商品列表")
    public ResultVm<List<PGoodsPageVm>> list(@RequestBody List<String> ids, @Schema(hidden = true) @User UserVo userVo) {
        return goodsService.list(ids, userVo);
    }
}
